﻿//---------------------------------------------------------------------------------
// Copyright 2011 Microsoft Corporation
// Licensed under the Microsoft Public License (MS-PL) (the "License"); 
// You may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.opensource.org/licenses/ms-pl.html
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR 
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, 
// INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 
// CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
// MERCHANTABLITY OR NON-INFRINGEMENT. 
// See the Microsoft Public License (MS-PL) for the specific language governing 
// permissions and limitations under the License.
//---------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Data.Services.Common;

namespace Microsoft.Telco.WindowsLive
{
	[EntityPropertyMapping("Updated", SyndicationItemProperty.Updated, SyndicationTextContentKind.Plaintext, false), EntityPropertyMapping("Contributor/Name", SyndicationItemProperty.ContributorName, SyndicationTextContentKind.Plaintext, false), EntityPropertyMapping("Contributor/Uri", SyndicationItemProperty.ContributorUri, SyndicationTextContentKind.Plaintext, false), DataServiceKey("Id"), EntityPropertyMapping("Id", SyndicationItemProperty.Id, SyndicationTextContentKind.Plaintext, false), EntityPropertyMapping("Title", SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, false), EntityPropertyMapping("Contributor/Email", SyndicationItemProperty.ContributorEmail, SyndicationTextContentKind.Plaintext, false), EntityPropertyMapping("Published", SyndicationItemProperty.Published, SyndicationTextContentKind.Plaintext, false), EntityPropertyMapping("Author/Name", SyndicationItemProperty.AuthorName, SyndicationTextContentKind.Plaintext, false), EntityPropertyMapping("Author/Email", SyndicationItemProperty.AuthorEmail, SyndicationTextContentKind.Plaintext, false), EntityPropertyMapping("Author/Uri", SyndicationItemProperty.AuthorUri, SyndicationTextContentKind.Plaintext, false)]
	public class LiveResource : INotifyPropertyChanged
	{
		// Fields
		private Person _Author;
		//private DataServiceCollection<Profile> _AuthorProfiles = new DataServiceCollection<Profile>(null, TrackingMode.None);
		private Person _Contributor;
		//private DataServiceCollection<Profile> _ContributorProfiles = new DataServiceCollection<Profile>(null, TrackingMode.None);
		private string _Id;
		private bool _IsDeleted;
		private DateTime _Published;
		private string _Title;
		private DateTime _Updated;
		private LiveDataContext dataContext;

		// Events
		public event PropertyChangedEventHandler PropertyChanged;

		// Methods
		public LiveDataContext GetDataContext()
		{
			return this.dataContext;
		}

		protected virtual void OnPropertyChanged(string property)
		{
			if (this.PropertyChanged != null)
			{
				this.PropertyChanged(this, new PropertyChangedEventArgs(property));
			}
		}

		internal void SetDataContext(LiveDataContext dataContext)
		{
			this.dataContext = dataContext;
		}

		public override string ToString()
		{
			return this.Title;
		}

		// Properties
		public Person Author
		{
			get
			{
				return this._Author;
			}
			internal set
			{
				this._Author = value;
				this.OnPropertyChanged("Author");
			}
		}

		//public DataServiceCollection<Profile> AuthorProfiles
		//{
		//    get
		//    {
		//        return this._AuthorProfiles;
		//    }
		//    internal set
		//    {
		//        this._AuthorProfiles = value;
		//        this.OnPropertyChanged("AuthorProfiles");
		//    }
		//}

		public Person Contributor
		{
			get
			{
				return this._Contributor;
			}
			set
			{
				this._Contributor = value;
				this.OnPropertyChanged("Contributor");
			}
		}

		//public DataServiceCollection<Profile> ContributorProfiles
		//{
		//    get
		//    {
		//        return this._ContributorProfiles;
		//    }
		//    internal set
		//    {
		//        this._ContributorProfiles = value;
		//        this.OnPropertyChanged("ContributorProfiles");
		//    }
		//}

		public string Id
		{
			get
			{
				return this._Id;
			}
			internal set
			{
				this._Id = value;
				this.OnPropertyChanged("Id");
			}
		}

		public bool IsDeleted
		{
			get
			{
				return this._IsDeleted;
			}
			internal set
			{
				this._IsDeleted = value;
				this.OnPropertyChanged("IsDeleted");
			}
		}

		public DateTime Published
		{
			get
			{
				return this._Published;
			}
			internal set
			{
				this._Published = value;
				this.OnPropertyChanged("Published");
			}
		}

		public string Title
		{
			get
			{
				return this._Title;
			}
			set
			{
				this._Title = value;
				this.OnPropertyChanged("Title");
			}
		}

		public DateTime Updated
		{
			get
			{
				return this._Updated;
			}
			internal set
			{
				this._Updated = value;
				this.OnPropertyChanged("Updated");
			}
		}
	}

}